/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.metadataRepository.transformation;

import cz.mzk.oai.metadataRepository.metadata.MarcRecord;
import cz.mzk.oai.metadataRepository.metadata.MetadataFormat;
import java.io.File;
import org.dom4j.Document;

/**
 *
 * @author Martin Řehánek (rehan at mzk.cz)
 */
public class MarcBasedXsltEseBuilder extends XsltSingleSourceConditionedBuilder {

    //TODO: "http://kramerius4.mzk.cz.*", "http://mapy.mzk.cz.*" 
    private static String[] urlPatterns = {"http://aleph.mzk.cz/adam.*", "http://imageserver.mzk.cz.*", "http://kramerius4.mzk.cz.*"};

    public MarcBasedXsltEseBuilder(File marcToEseXslt) throws TransformationException {
        super(marcToEseXslt, MetadataFormat.marc21, MetadataFormat.ese);
    }

    @Override
    boolean canBeTransformed(Document sourceDocument) {
        MarcRecord record = new MarcRecord(sourceDocument);
        if (!record.notEmpty856()) {
            return false;
        }
        for (String pattern : urlPatterns) {
            if (record.someLinkMatches(pattern)) {
                return true;
            }
        }
        return false;
    }
}
